package com.rabbit.mq.impl;

import com.rabbit.config.MqProducerProperties;
import com.rabbit.entity.Notice;
import com.rabbit.mq.NoticeFanoutProducer;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author yuhuan
 * @date 2025/4/18
 */
@Service
public class NoticeFanoutProducerImpl implements NoticeFanoutProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private MqProducerProperties mqProperties;

    @Override
    public void sendNoticeMessage(Notice message) {
        message.setDataId(UUID.randomUUID().toString());
        System.out.println(String.format("正在推送通知[%s]，msg: %s", message.getCode(), message));
        rabbitTemplate.convertAndSend(mqProperties.getNoticeExchangeName(), "", message);
    }
}
